package entities;

import interfaze.SpaceInvadersGamingPanel;

import java.awt.Image;

import javax.swing.ImageIcon;

import logic.Utilities;

@SuppressWarnings("serial")
public class RelSpeedUp extends PowerUp {
	private ImageIcon icon;
	/**
	 * this constructor creates a RelSpeedUp powerup on the specified panel given these attributes:
	 * this constructor 
	 * @param x
	 * @param y coordinates
	 * @param dx
	 * @param dy speed
	 * @param xScale
	 * @param yScale scale
	 * @param p panel to which this power up belongs
	 */
	public RelSpeedUp(int x, int y, int dx, int dy, float xScale, float yScale, SpaceInvadersGamingPanel p) {
		super(x, y, dx, dy);
		this.p=p;
		Image image = Utilities.loadImage("res/RELOAD_SPEEDPU.png");
		if(xScale != 1 || yScale != 1) {
			image = Utilities.resizeImage(xScale, yScale, "res/RELOAD_SPEEDPU.png");
		}
		icon = new ImageIcon(image);
		this.setIcon(icon);
		this.width = image.getWidth(null);
		this.height = image.getHeight(null);
		this.setBounds((int)this.x, (int)this.y, this.width, this.height);
		lastUpdate=System.currentTimeMillis();
	}
	/**
	 * this method checks if the player has picked up the power up and increases its reload speed 
	 */
	public void pickedUp(Defender d){
		if (this.getBounds().intersects(d.getBounds())&&this.isVisible()){
			d.incRelaod();
			this.setVisible(false);
		}
	}
}
